﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;

public class House : Seletable {

	public GameObject soundman;//remove later

	public Image _Image;

	public Sprite _sprite;

	public Fire _fire;

	public TurnSystem _turnSystem;

	public int occupantsno;
	public occupants occupants;
	private List<House> mNeighbours = new List<House>();

	private List<FireMan> mFireMen = new List<FireMan> ();

	private HashSet<FireTruck> mFireTrucks = new HashSet<FireTruck> ();

	private TurnSystem mTurnSystem;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	//
	// getter setter
	//

	public void hackToggle() {
		_turnSystem.selectHouse(this);
	}

	public void UpdateOccs()
	{
		occupants.update(occupantsno);
	}

	public bool isOnFire() {
		return _fire.isOnFire();
	}

	public void startFire() {
		_fire.startFire ();
		soundman.GetComponent<Soundman>().playsound(6);
	}

	public void SetTurnSystem(TurnSystem houseGenerator) {
		mTurnSystem = houseGenerator;
	}


	public void AddNeighbour(House house) {
		mNeighbours.Add (house);
	}


	new public void Select() {
		mTurnSystem.UnselectAll ();
		base.Select ();
		foreach (House house in mNeighbours) {
			house.HighLight();
		}
		soundman.GetComponent<Soundman>().playsound(1);//
	}

	public void showNeighbours() {
		foreach (House house in mNeighbours) {
			house.HighLight();
		}
	}

	public List<FireMan> getFireMen() {
		return mFireMen;
	}

	public List<House> Neighbours {
		get {
			return mNeighbours;
		}
	}

	public HashSet<FireTruck> FireTrucks {
		get {
			return mFireTrucks;
		}
	}

	public void AddFireTruck(FireTruck fireTuck) {
		mFireTrucks.Add (fireTuck);

		fireTuck.AssignedToHouse (this);
	}

	public void RemoveFireTruck(FireTruck fireTruck) {
		mFireTrucks.Remove (fireTruck);
		fireTruck.RemovedFromHouse ();
	}

}
